<script>
  var numberOfPairs = function (nums) {
    const obj = {};
    nums.forEach(num=>obj[num]?obj[num]++:obj[num]=1);
    const ans = [0,0];
    for(let key in obj){
      const a = Math.floor(obj[key]/2);
      const b = obj[key]%2;
      ans[0]+=a;
      ans[1]+=b;
    }
    return ans;
  };
  console.log(numberOfPairs([1, 3, 2, 1, 3, 2, 2]));
</script>